<!DOCTYPE html>
<html>
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel='stylesheet' href='style.css' type='text/css'>
    </head>

    <body class="page" onbeforeunload="stop()" onunload="stop()">
        <div class="browser"></div>

        <script src="../../lib/core/vtkweb-loader.js" load="core-min, filebrowser"></script>
        <script type="text/javascript">
            var config = {
                sessionManagerURL: vtkWeb.properties.sessionManagerURL,
                application: "filebrowser"
            },
            stop = vtkWeb.NoOp,
            start = function(serverConnection) {
                connection = serverConnection;

                // Create file browser widget
                connection.session.call('file.server.directory.list',['.']).then(function(files){
                    $('.browser').fileBrowser({data: [files], session: connection.session}).bind('file-click directory-click directory-not-found file-group-click', function(e){
                        console.log(e.type + " click: " + e.name + " - path: " + e.path );
                        if(e.hasOwnProperty('relativePathList')) {
                            console.log(e.relativePathList);
                        }
                    });;
                });

                // Method call at exit time
                stop = function() {
                    if (connection.session) {
                        connection.session.call('application.exit');
                        connection.session.close();
                        connection.session = null;
                    }
                };
            };

            // Try to launch the remote process
            vtkWeb.smartConnect(config, start, function(code,reason){
                console.log(reason);
            });
        </script>
    </body>
</html>
